package learn.basic;

import java.io.File;
import java.io.FileNotFoundException;

import org.gephi.data.attributes.api.AttributeColumn;
import org.gephi.data.attributes.api.AttributeController;
import org.gephi.data.attributes.api.AttributeModel;
import org.gephi.data.attributes.api.AttributeType;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.Node;
import org.gephi.io.importer.api.Container;
import org.gephi.io.importer.api.EdgeDefault;
import org.gephi.io.importer.api.ImportController;
import org.gephi.io.processor.plugin.DefaultProcessor;
import org.gephi.project.api.ProjectController;
import org.gephi.project.api.Workspace;
import org.openide.util.Lookup;

public class ManipulateAttributes {

	public static void main(String[] args) {
		ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
		pc.newProject();
		Workspace workspace = pc.getCurrentWorkspace();
		
		ImportController importController = Lookup.getDefault().lookup(ImportController.class);
		
		Container container;
		try {
			File file = new File("Data/Power Grid.gml");
			container = importController.importFile(file);
			container.getLoader().setEdgeDefault(EdgeDefault.DIRECTED);
			container.setAllowAutoNode(false);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return;
		}
		
		importController.process(container, new DefaultProcessor(), workspace);
		
		AttributeController ac = Lookup.getDefault().lookup(AttributeController.class);
		AttributeModel model = ac.getModel();
		for (AttributeColumn col : model.getNodeTable().getColumns())
			System.out.println(col);
		
		AttributeColumn testCol = model.getNodeTable().addColumn("test", AttributeType.BOOLEAN);
		
		GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getModel();
		for (Node n : graphModel.getGraph().getNodes())
			n.getNodeData().getAttributes().setValue(testCol.getIndex(), Boolean.TRUE);
	}

}